package com.us.usws.site.ipodium.share;

public abstract class Pagination {

	private int maxPageNum = 10;

	private int pageNo = 1;

	private int pageCount;

	private String baseUrl;

	public static enum Style {
		Ipodium
	}

	public Pagination(int pageNo, int pageCount, String baseUrl) {
		this.pageNo = pageNo;
		this.pageCount = pageCount;
		this.baseUrl = baseUrl;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public String getBaseUrl() {
		return baseUrl;
	}

	public void setBaseUrl(String baseUrl) {
		this.baseUrl = baseUrl;
	}

	public abstract Style getStyle();

	public abstract String getCurrentPageHTML(int pg);

	public abstract String getLinkedPageHTML(int pg, String displayName);

	public String getPagination() {
		StringBuilder sb = new StringBuilder();
		if (pageNo > 1) {
			//first page
			sb.append(getLinkedPageHTML(1, "\u9996\u9875")).append("\n");
			//prev page
			sb.append(getLinkedPageHTML(pageNo - 1, "\u4e0a\u4e00\u9875")).append("\n");
		}

		int start, end;
		if (pageCount > maxPageNum) {
			start = (pageNo - 1) / maxPageNum * maxPageNum + 1;
			end = start + maxPageNum - 1;
			if (end > pageCount) {
				end = pageCount;
			}
		} else {
			start = 1;
			end = pageCount;
		}
		for (int i = start; i <= end; i++) {
			if (pageNo == i) {
				sb.append(getCurrentPageHTML(i)).append("\n");
			} else {
				sb.append(getLinkedPageHTML(i, Integer.toString(i))).append("\n");
			}
		}

		if (pageNo < pageCount) {
			//next page
			sb.append(getLinkedPageHTML(pageNo + 1, "\u4e0b\u4e00\u9875")).append("\n");
			//last page
			sb.append(getLinkedPageHTML(pageCount, "\u5c3e\u9875"));
		}
		return sb.toString();
	}

	public int getMaxPageNum() {
		return maxPageNum;
	}

	public void setMaxPageNum(int maxPageNum) {
		this.maxPageNum = maxPageNum;
	}

}
